package com.coolcode.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.coolcode.entity.UserInfo;
import com.coolcode.mapper.UserInfoMapper;
import com.coolcode.service.UserInfoService;
import com.coolcode.util.BCryptUtil;
import com.coolcode.util.SecurityContextUtil;
import org.springframework.stereotype.Service;

import java.util.Date;


/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2023-01-30
 */
@Service
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements UserInfoService {

    public boolean save(UserInfo entity) {
        entity.setPassword(BCryptUtil.encode(entity.getPassword()));
        entity.setEnabled(true);
        entity.setCreateTime(new Date());
        entity.setCreatedBy(SecurityContextUtil.getLoginUserInfo().getUserInfo().getId());

        return super.save(entity);
    }

    public boolean updateById(UserInfo entity){

        entity.setPassword(BCryptUtil.encode(entity.getPassword()));
        entity.setUpdatedTime(new Date());
        entity.setUpdatedBy(SecurityContextUtil.getLoginUserInfo().getUserInfo().getId());

        return super.updateById(entity);
    }
}
